home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Skunkware 5
/
Skunkware 5.iso
/
src
/
X11
/
xsw
/
psio.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-09
|
20KB
|
756 lines
/*
* @(#) psio.c 12.1 95/05/09 SCOINC
*/
/***************************************************************************
*
* Copyright (c) 1990-1993 The Santa Cruz Operation, Inc.
*
* All rights reserved. No part of this program or publication may be
* reproduced, transmitted, transcribed, stored in a retrieval system,
* or translated into any language or computer language, in any form or
* by any means, electronic, mechanical, magnetic, optical, chemical,
* biological, or otherwise, without the prior written permission of:
*
* The Santa Cruz Operation , Inc. (408) 425-7222
* 400 Encinal St., Santa Cruz, California 95060 USA
*
**************************************************************************/
/*
* Modification History
*
* S002, 15-Sep-93, rickra
* If def'ed out some old code for now... Should remove it....
* Lots of little bug fixes....
*
* S001, 27-May-93, rickra
* Alot of stuff has been done.....
*
* S000, 30-Sep-92, rickra
* Added copyright and modification history
* Change hard coded color referneces to user configurable.
*/
/*+-------------------------------------------------------------------------
psio.c - XSW proc status detail
Defined functions:
display_io_proc_stat(x,y,iproc)
--------------------------------------------------------------------------*/
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Intrinsic.h>
#include <X11/Shell.h>
#include <X11/StringDefs.h>
#include <Xm/Xm.h>
#include <Xm/MainW.h>
#include <Xm/DrawingA.h>
#include "include/unixincs.h"
#include "include/resources.h"
#include "include/xswboth.h"
#include "include/buttons.h"
#include "include/libkmem.h"
#include "include/libmem.h"
#include "include/libswap.h"
#include "include/xsw.h"
#include "include/psio.h"
extern struct NetworkXswStruct *current_server;
extern struct my_user_struct user;
extern struct my_user_struct old_user;
/*+-------------------------------------------------------------------------
ppproc_io_user_compare(ppp1,ppp2)
--------------------------------------------------------------------------*/
ppproc_io_user_compare (ppp1, ppp2)
struct my_proc_struct **ppp1;
struct my_proc_struct **ppp2;
{
if (((*ppp1) -> p_pid == 32767) && ((*ppp2) -> p_pid == 32767))
return (0);
else if ((*ppp1) -> p_pid == 32767)
return (1);
else if ((*ppp2) -> p_pid == 32767)
return (-1);
if (current_server -> ps_io_sort_order == 1)
return (strcmp ((*ppp2) -> name, (*ppp1) -> name));
else
return (strcmp ((*ppp1) -> name, (*ppp2) -> name));
} /* end of ppproc_io_user_compare */
/*+-------------------------------------------------------------------------
ppproc_io_pid_compare(ppp1,ppp2)
--------------------------------------------------------------------------*/
ppproc_io_pid_compare (ppp1, ppp2)
struct my_proc_struct **ppp1;
struct my_proc_struct **ppp2;
{
if (((*ppp1) -> p_pid == 32767) && ((*ppp2) -> p_pid == 32767))
return (0);
else if ((*ppp1) -> p_pid == 32767)
return (1);
else if ((*ppp2) -> p_pid == 32767)
return (-1);
if (current_server -> ps_io_sort_order == 1)
return ((*ppp2) -> p_pid - (*ppp1) -> p_pid);
else
return ((*ppp1) -> p_pid - (*ppp2) -> p_pid);
} /* end of ppproc_io_pid_compare */
/*+-------------------------------------------------------------------------
ppproc_io_cmd_compare(ppp1,ppp2)
--------------------------------------------------------------------------*/
ppproc_io_cmd_compare (ppp1, ppp2)
struct my_proc_struct **ppp1;
struct my_proc_struct **ppp2;
{
struct my_user_struct user1;
struct my_user_struct user2;
int i, j;
i = get_user (&(**ppp1), &user1);
j = get_user (&(**ppp2), &user2);
if (((*ppp1) -> p_pid == 32767) && ((*ppp2) -> p_pid == 32767))
return (0);
else if ((*ppp1) -> p_pid == 32767)
return (1);
else if ((*ppp2) -> p_pid == 32767)
return (-1);
if (current_server -> ps_io_sort_order == 1)
return (strcmp (user2.u_psargs, user1.u_psargs));
else
return (strcmp (user1.u_psargs, user2.u_psargs));
} /* end of ppproc_io_cmd_compare */
/*+-------------------------------------------------------------------------
ppproc_io_total_compare(ppp1,ppp2)
--------------------------------------------------------------------------*/
ppproc_io_total_compare (ppp1, ppp2)
struct my_proc_struct **ppp1;
struct my_proc_struct **ppp2;
{
struct my_user_struct user1;
struct my_user_struct user2;
struct my_user_struct old_user1;
struct my_user_struct old_user2;
int i, j, k, l;
i = get_user (&(**ppp1), &user1);
j = get_user (&(**ppp2), &user2);
k = get_old_user (&(**ppp1), &old_user1);
l = get_old_user (&(**ppp2), &old_user2);
if (((*ppp1) -> p_pid == 32767) && ((*ppp2) -> p_pid == 32767))
return (0);
else if (((*ppp1) -> p_pid == 32767) || (!i))
return (1);
else if (((*ppp2) -> p_pid == 32767) || (!j))
return (-1);
if (current_server -> ps_io_sort_order == 1)
{
if (current_server -> ps_io_display_mode == 9)
return ((user2.u_iow + user2.u_ior) -
(user1.u_iow + user1.u_ior));
else
return (((user2.u_iow + user2.u_ior) -
(old_user2.u_iow + old_user2.u_ior)) -
((user1.u_iow + user1.u_ior) -
(old_user1.u_iow + old_user1.u_ior)));
}
else
{
if (current_server -> ps_io_display_mode == 9)
return ((user1.u_iow + user1.u_ior) -
(user2.u_iow + user2.u_ior));
else
return (((user1.u_iow + user1.u_ior) -
(old_user1.u_iow + old_user1.u_ior)) -
((user2.u_iow + user2.u_ior) -
(old_user2.u_iow + old_user2.u_ior)));
}
} /* end of ppproc_io_total_compare */
/*+-------------------------------------------------------------------------
ppproc_io_write_compare(ppp1,ppp2)
--------------------------------------------------------------------------*/
ppproc_io_write_compare (ppp1, ppp2)
struct my_proc_struct **ppp1;
struct my_proc_struct **ppp2;
{
struct my_user_struct user1;
struct my_user_struct user2;
struct my_user_struct old_user1;
struct my_user_struct old_user2;
int i, j, k, l;
i = get_user (&(**ppp1), &user1);
j = get_user (&(**ppp2), &user2);
k = get_old_user (&(**ppp1), &old_user1);
l = get_old_user (&(**ppp2), &old_user2);
if (((*ppp1) -> p_pid == 32767) && ((*ppp2) -> p_pid == 32767))
return (0);
else if (((*ppp1) -> p_pid == 32767) || (!i))
return (1);
else if (((*ppp2) -> p_pid == 32767) || (!j))
return (-1);
if (current_server -> ps_io_sort_order == 1)
{
if (current_server -> ps_io_display_mode == 9)
return ((user2.u_iow) -
(user1.u_iow));
else
return (((user2.u_iow) -
(old_user2.u_iow)) -
((user1.u_iow) -
(old_user1.u_iow)));
}
else
{
if (current_server -> ps_io_display_mode == 9)
return ((user1.u_iow) -
(user2.u_iow));
else
return (((user1.u_iow) -
(old_user1.u_iow)) -
((user2.u_iow) -
(old_user2.u_iow)));
}
} /* end of ppproc_io_write_compare */
/*+-------------------------------------------------------------------------
ppproc_io_read_compare(ppp1,ppp2)
--------------------------------------------------------------------------*/
ppproc_io_read_compare (ppp1, ppp2)
struct my_proc_struct **ppp1;
struct my_proc_struct **ppp2;
{
struct my_user_struct user1;
struct my_user_struct user2;
struct my_user_struct old_user1;
struct my_user_struct old_user2;
int i, j, k, l;
i = get_user (&(**ppp1), &user1);
j = get_user (&(**ppp2), &user2);
k = get_old_user (&(**ppp1), &old_user1);
l = get_old_user (&(**ppp2), &old_user2);
if (((*ppp1) -> p_pid == 32767) && ((*ppp2) -> p_pid == 32767))
return (0);
else if (((*ppp1) -> p_pid == 32767) || (!i))
return (1);
else if (((*ppp2) -> p_pid == 32767) || (!j))
return (-1);
if (current_server -> ps_io_sort_order == 1)
{
if (current_server -> ps_io_display_mode == 9)
return ((user2.u_ior) -
(user1.u_ior));
else
return (((user2.u_ior) -
(old_user2.u_ior)) -
((user1.u_ior) -
(old_user1.u_ior)));
}
else
{
if (current_server -> ps_io_display_mode == 9)
return ((user1.u_ior) -
(user2.u_ior));
else
return (((user1.u_ior) -
(old_user1.u_ior)) -
((user2.u_ior) -
(old_user2.u_ior)));
}
} /* end of ppproc_io_read_compare */
/*+-------------------------------------------------------------------------
ppproc_io_swap_compare(ppp1,ppp2)
--------------------------------------------------------------------------*/
ppproc_io_swap_compare (ppp1, ppp2)
struct my_proc_struct **ppp1;
struct my_proc_struct **ppp2;
{
struct my_user_struct user1;
struct my_user_struct user2;
struct my_user_struct old_user1;
struct my_user_struct old_user2;
int i, j, k, l;
i = get_user (&(**ppp1), &user1);
j = get_user (&(**ppp2), &user2);
k = get_old_user (&(**ppp1), &old_user1);
l = get_old_user (&(**ppp2), &old_user2);
if (((*ppp1) -> p_pid == 32767) && ((*ppp2) -> p_pid == 32767))
return (0);
else if (((*ppp1) -> p_pid == 32767) || (!i))
return (1);
else if (((*ppp2) -> p_pid == 32767) || (!j))
return (-1);
if (current_server -> ps_io_sort_order == 1)
{
if (current_server -> ps_io_display_mode == 9)
return ((user2.u_iosw) -
(user1.u_iosw));
else
return (((user2.u_iosw) -
(old_user2.u_iosw)) -
((user1.u_iosw) -
(old_user1.u_iosw)));
}
else
{
if (current_server -> ps_io_display_mode == 9)
return ((user1.u_iosw) -
(user2.u_iosw));
else
return (((user1.u_iosw) -
(old_user1.u_iosw)) -
((user2.u_iosw) -
(old_user2.u_iosw)));
}
} /* end of ppproc_io_swap_compare */
/*+-------------------------------------------------------------------------
ppproc_io_char_compare(ppp1,ppp2)
--------------------------------------------------------------------------*/
ppproc_io_char_compare (ppp1, ppp2)
struct my_proc_struct **ppp1;
struct my_proc_struct **ppp2;
{
struct my_user_struct user1;
struct my_user_struct user2;
struct my_user_struct old_user1;
struct my_user_struct old_user2;
int i, j, k, l;
i = get_user (&(**ppp1), &user1);
j = get_user (&(**ppp2), &user2);
k = get_old_user (&(**ppp1), &old_user1);
l = get_old_user (&(**ppp2), &old_user2);
if (((*ppp1) -> p_pid == 32767) && ((*ppp2) -> p_pid == 32767))
return (0);
else if (((*ppp1) -> p_pid == 32767) || (!i))
return (1);
else if (((*ppp2) -> p_pid == 32767) || (!j))
return (-1);
if (current_server -> ps_io_sort_order == 1)
{
if (current_server -> ps_io_display_mode == 9)
return ((user2.u_ioch) -
(user1.u_ioch));
else
return (((user2.u_ioch) -
(old_user2.u_ioch)) -
((user1.u_ioch) -
(old_user1.u_ioch)));
}
else
{
if (current_server -> ps_io_display_mode == 9)
return ((user1.u_ioch) -
(user2.u_ioch));
else
return (((user1.u_ioch) -
(old_user1.u_ioch)) -
((user2.u_ioch) -
(old_user2.u_ioch)));
}
} /* end of ppproc_io_char_compare */
/*+-------------------------------------------------------------------------
display_io_proc_stat(x,y,iproc)
00000000001111111111222222222233333333334444444444555555555566666666667777777777
01234567890123456789012345678901234567890123456789012345678901234567890123456789
USER PID CPU PRI NI UCPU SCPU SIZE TTY CMD
#!########X ##### ### ### ## ###### ###### #### ### ########
--------------------------------------------------------------------------*/
void
display_io_proc_stat (window, display, gc, pixmap, x, y, iproc)
Window window;
Display *display;
GC gc;
Pixmap pixmap;
int x;
int y;
register int iproc;
{
int x2 = x;
register int positioned = 0;
register struct my_proc_struct *tproc = current_server -> pprocs[iproc];
struct my_proc_struct *oproc = current_server -> poldprocs[iproc];
int got_user;
int got_old_user;
char *p_stat_str = " sRzdipx"; /* dependent on values of
* SSLEEP etc */
char *cptr;
char s80[80];
int fwidth = FWIDTH;
unsigned long pixel;
struct ps_io_pixel_struct *pixel_list = NULL;
pixel_list = (struct ps_io_pixel_struct *)
calloc (1, sizeof (struct ps_io_pixel_struct));
pixel = colorPSioIdle.pixel;
got_user = get_user (tproc, &user);
/*
* Clear the line.....
*/
XSetForeground (display, gc, background);
XFillRectangle (display, pixmap, gc,0, y,
current_server -> SEPERATE_WINDOWS_LIST[BUTTON_ps_io].draw_width,
FHEIGHT);
if (got_user)
{
if (got_old_user = get_old_user (tproc, &old_user))
{
if (old_user.u_iosw != user.u_iosw)
pixel_list -> iosw_pixel = colorPSioActive.pixel;
else
pixel_list -> iosw_pixel = pixel;
if (old_user.u_ioch != user.u_ioch)
pixel_list -> ioch_pixel = colorPSioActive.pixel;
else
pixel_list -> ioch_pixel = pixel;
if (old_user.u_ior != user.u_ior)
pixel_list -> ior_pixel = colorPSioActive.pixel;
else
pixel_list -> ior_pixel = pixel;
if (old_user.u_iow != user.u_iow)
pixel_list -> iow_pixel = colorPSioActive.pixel;
else
pixel_list -> iow_pixel = pixel;
if ((old_user.u_iow + old_user.u_ior) !=
(user.u_iow + user.u_ior))
pixel_list -> total_pixel = colorPSioActive.pixel;
else
pixel_list -> total_pixel = pixel;
}
else
{
pixel = colorPSioNew.pixel;
pixel_list -> iosw_pixel = pixel;
pixel_list -> ioch_pixel = pixel;
pixel_list -> ior_pixel = pixel;
pixel_list -> iow_pixel = pixel;
pixel_list -> total_pixel = pixel;
}
}
/*
pixel = colorPSioIdle.pixel;
got_user = get_user (tproc, &user);
if (got_user)
{
if (got_old_user = get_old_user (tproc, &old_user))
{
if ((old_user.u_iow + old_user.u_ior) !=
(user.u_iow + user.u_ior))
pixel = colorPSioActive.pixel;
}
else
pixel = colorPSioNew.pixel;
}
*/
(void) sprintf (s80, "%-8s ", tproc -> name);
x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y, pixmap, pixel, s80);
s80[0] = (tproc -> p_uid != tproc -> p_suid) ? '#' : ' ';
s80[1] = ' ';
s80[2] = 0;
x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y, pixmap, pixel, s80);
(void) sprintf (s80, "%6d ", tproc -> p_pid);
x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y, pixmap, pixel, s80);
if (got_user)
{
if (current_server -> ps_io_display_mode == 9)
{
(void) sprintf (s80, "%6d ",
user.u_iosw);
x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y,
pixmap, pixel_list -> iosw_pixel, s80);
(void) sprintf (s80, "%12d ",
user.u_ioch);
x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y,
pixmap, pixel_list -> ioch_pixel, s80);
(void) sprintf (s80, "%6d ",
user.u_ior);
x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y,
pixmap, pixel_list -> ior_pixel, s80);
(void) sprintf (s80, "%6d ",
user.u_iow);
x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y,
pixmap, pixel_list -> iow_pixel, s80);
(void) sprintf (s80, "%8d ",
(user.u_iow + user.u_ior));
x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y,
pixmap, pixel_list -> total_pixel, s80);
}
else
{
(void) sprintf (s80, "%6d ",
user.u_iosw - old_user.u_iosw);
x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y,
pixmap, pixel_list -> iosw_pixel, s80);
(void) sprintf (s80, "%12d ",
user.u_ioch - old_user.u_ioch);
x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y,
pixmap, pixel_list -> ioch_pixel, s80);
(void) sprintf (s80, "%6d ",
user.u_ior - old_user.u_ior);
x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y,
pixmap, pixel_list -> ior_pixel, s80);
(void) sprintf (s80, "%6d ",
user.u_iow - old_user.u_iow);
x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y,
pixmap, pixel_list -> iow_pixel, s80);
(void) sprintf (s80, "%8d ",
(user.u_iow + user.u_ior) - (old_user.u_iow + old_user.u_ior));
x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y,
pixmap, pixel_list -> total_pixel, s80);
}
}
else
x2 += disp_info_text (window, display, gc, DrawAreaXYWH, x2, y, pixmap, pixel, "------ ------------ ------ ------ -------- ");
/*
XClearArea (display, window, x2, y, DrawAreaXYWH.width - x2, FHEIGHT, 0);
*/
XSetForeground (display, gc, background);
XFillRectangle (display, pixmap, gc, x2, y,
current_server -> SEPERATE_WINDOWS_LIST[BUTTON_ps_io].width - x2,
FHEIGHT);
XSetForeground (display, gc, pixel);
if (got_user)
{
/*
XDrawString (display, window, gc, x2, y + FASCENT,
*/
XDrawString (display, pixmap, gc, x2, y + FASCENT,
user.u_psargs, strlen (user.u_psargs));
}
else
{
switch (tproc -> p_stat)
{
case SZOMB:
cptr = "<zombie>";
break;
case SXBRK:
cptr = "<xbreak>";
break;
case SIDL:
cptr = "<in creation>";
break;
default:
cptr = "<swap in progress>";
}
/*
XDrawString (display, window, gc, x2, y + FASCENT, cptr, strlen (cptr));
*/
XDrawString (display, pixmap, gc, x2, y + FASCENT, cptr, strlen (cptr));
}
free (pixel_list);
} /* end of display_io_proc_stat */
/*+-------------------------------------------------------------------------
update_ps_io(SP)
--------------------------------------------------------------------------*/
void
update_ps_io (SP)
struct NetworkXswStruct *SP;
{
Window window = SP -> SEPERATE_WINDOWS_LIST[BUTTON_ps_io].window;
Display *display = SP -> SEPERATE_WINDOWS_LIST[BUTTON_ps_io].display;
GC gc = SP -> SEPERATE_WINDOWS_LIST[BUTTON_ps_io].gc;
Pixmap pixmap = SP -> SEPERATE_WINDOWS_LIST[BUTTON_ps_io].pixmap;
int x = 0;
int y = 0;
int ps_procs_to_disp;
int button_num;
register int iproc;
int fheight = FHEIGHT;
int i;
int current_ps_number = 0;
int got_user;
int got_old_user;
struct my_proc_struct *tproc;
sort_procs (BUTTON_ps_io);
y = 0;
if (SP -> ps_io_display_mode == 9)
{
for (iproc = 0; iproc < SP -> nprocs; iproc++)
{
display_io_proc_stat (window, display, gc, pixmap,
x, y + (iproc * fheight),
iproc);
}
y += (iproc * fheight);
}
else
{
current_ps_number = 0;
for (iproc = 0; iproc < SP -> nprocs; iproc++)
{
tproc = SP -> pprocs[iproc];
got_user = get_user (tproc, &user);
if (got_user)
{
if (got_old_user = get_old_user (tproc, &old_user))
{
if (got_old_user)
{
if ((((old_user.u_ior + old_user.u_iow) !=
(user.u_ior + user.u_iow)) &&
((user.u_ior - old_user.u_ior) >= 0) &&
((user.u_iow - old_user.u_iow) >= 0)) ||
(old_user.u_ioch != user.u_ioch)
)
{
display_io_proc_stat (window, display, gc, pixmap,
x,
y + (current_ps_number * fheight),
iproc);
current_ps_number++;
}
}
}
}
}
y += (current_ps_number * fheight);
}
XSetForeground (display, gc, background);
XFillRectangle (display, pixmap, gc,
x, y,
SP -> SEPERATE_WINDOWS_LIST[BUTTON_ps_io].draw_width,
SP -> SEPERATE_WINDOWS_LIST[BUTTON_ps_io].draw_height);
} /* end of update_ps_io */
/* vi: set tabstop=4 shiftwidth=4: */
/* end of psio.c */